package com.bawei.test

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.PersistableBundle
import android.util.Log
import android.view.View
import android.widget.VideoView

/**
 * 数据都bundle实现
 * onSaveInstanceState():保存数据，页面销毁
 * onCreate()：可以恢复数据，但是不保证有数据可以恢复，因为主要用于创建activity
 * onRestoreInstanceState（）:恢复数据,页面销毁的时候使用onSaveInstanceState()保存数据，
 *
 */
class VideoActivity : AppCompatActivity() {
    private lateinit var videoView:VideoView
    //可以用来恢复数据，bundle可能为空
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_video)
        videoView = findViewById(R.id.vv)
        videoView.setVideoPath("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
        videoView.setOnPreparedListener{
            videoView.start()
        }
        Log.d("ytx", "onCreate "+savedInstanceState?.getString("data"))
    }
    //恢复数据：bundle必定不是空，只有调用onSaveInstanceState保存数据，才能触发onRestoreInstanceState恢复数据
    override fun onRestoreInstanceState(savedInstanceState: Bundle) {
        super.onRestoreInstanceState(savedInstanceState)
        Log.d("ytx", "onRestoreInstanceState:恢复数据 "+savedInstanceState.getString("data"))
    }
    //保存数据
    override fun onSaveInstanceState(outState: Bundle) {
        Log.d("ytx", "onSaveInstanceState:保存数据 ")
        super.onSaveInstanceState(outState)
        outState.putString("data","你好")
    }



}